package flc.ast.adapter;

import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.FrameBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.view.container.StkFrameLayout;

public class ColorAdapter extends StkProviderMultiAdapter<FrameBean> {
    public ColorAdapter() {
        super(8);
        addItemProvider(new ColorItemProvider());
    }

    private class ColorItemProvider extends BaseItemProvider<FrameBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_color;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, FrameBean frameBean) {
            StkFrameLayout crl = baseViewHolder.getView(R.id.crl);
            if (frameBean.getFrameColor().equals("#FFFFFF")) {
                crl.setBackgroundResource(R.drawable.white_bg);
            } else {
                crl.setBackgroundColor(Color.parseColor(frameBean.getFrameColor()));
            }
            if (frameBean.isSelected()){
                baseViewHolder.getView(R.id.ivColorSelector).setVisibility(View.VISIBLE);
            }else {
                baseViewHolder.getView(R.id.ivColorSelector).setVisibility(View.INVISIBLE);
            }
        }
    }
}
